﻿/* 分页参数类 by match on 20110425 */
namespace ShopB2C.Core.Entities {
    using System.Collections.Generic;
    using System.IO;
    using ShopB2C.Core.Enums;
    using ShopB2C.Core.Helpers;
    using ShopB2C.Core.Resources;
    /// <summary>
    /// 分页参数类
    /// </summary>
    public class PagerParams {
        public PagerParams() {
            Dictionary<PagerResourceKey, string> pagerLanguage = new Dictionary<PagerResourceKey, string>();
            pagerLanguage.Add(PagerResourceKey.LongTotal, CoreResources.Pager_LongTotal);
            pagerLanguage.Add(PagerResourceKey.Previous, CoreResources.Pager_Previous);
            pagerLanguage.Add(PagerResourceKey.Next, CoreResources.Pager_Next);
            pagerLanguage.Add(PagerResourceKey.Go, CoreResources.Pager_Go);
            pagerLanguage.Add(PagerResourceKey.First, CoreResources.Pager_First);
            pagerLanguage.Add(PagerResourceKey.Last, CoreResources.Pager_Last);
            pagerLanguage.Add(PagerResourceKey.ShortTotal, CoreResources.Pager_ShortTotal);

            this.TextWriter = null;
            this.Url = string.Empty;
            this.PageSize = 20;
            this.PageIndex = 1;
            this.RecordCount = 0;
            this.PageSizeList = "1,5,20,50,100";
            this.Language = pagerLanguage;
            this.PagerType = PagerType.EntireAndSkip;
            this.PagerTotal = PagerTotal.LongTotal;
        }
        /// <summary>
        /// 执行
        /// </summary>
        public void Execute() {
            if (this.PagerType == PagerType.PreviousAndNextAndNum) {
                new ControlPagerHelper() {
                    PagerParams = this
                }.Create();
            }
            else {
                new PagerHelper(this).Create();
            }
        }
        /// <summary>
        /// HtmlTextWriter 承载对象
        /// </summary>
        public TextWriter TextWriter { get; set; }
        /// <summary>
        /// Url 地址, 当前页号为 p={0}, 指定的每页显示记录数为 s={1}
        /// </summary>
        public string Url { get; set; }
        /// <summary>
        /// 每页显示记录
        /// </summary>
        public int PageSize { get; set; }
        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex { get; set; }
        /// <summary>
        /// 总记录数
        /// </summary>
        public int RecordCount { get; set; }
        /// <summary>
        /// 总页数, 只读
        /// </summary>
        public int PageCount { get; private set; }
        /// <summary>
        /// 可自定义每页显示记录数列表, "," 分隔
        /// </summary>
        public string PageSizeList { get; set; }
        /// <summary>
        /// 分页类语言
        /// </summary>
        public Dictionary<PagerResourceKey, string> Language { get; set; }
        /// <summary>
        /// 分页类型
        /// </summary>
        public PagerType PagerType { get; set; }
        /// <summary>
        /// 描述字符串
        /// </summary>
        public PagerTotal PagerTotal { get; set; }
    }
}
